<template>
	<view class="template-collect tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>


		<view class="" :style="{paddingTop: vuex_custom_bar_height + 'px'}">

			<view class="" style="margin-bottom: 120rpx;">

				<!-- 图文信息 -->
				<block v-for="(item,index) in news">
					<view class="blogger__item" :key="index">
						<view class="blogger__author tn-flex tn-flex-row-between tn-flex-col-center">
							<view class="justify__author__info">
								<view class="tn-flex tn-flex-row-center">
									<view class="tn-flex tn-flex-row-center tn-flex-col-center">
										<view class="">
											<tn-avatar class="" shape="circle" :src="item.userAvatar" size="lg">
											</tn-avatar>
										</view>
										<view class="tn-padding-right tn-text-ellipsis">
											<view class="tn-padding-right tn-padding-left-sm tn-text-bold tn-text-lg">
												{{ item.userName }}
											</view>
											<view
												class="tn-padding-right tn-padding-left-sm tn-padding-top-xs tn-color-gray">
												{{ item.date }}
											</view>
										</view>
									</view>
								</view>
							</view>
							<view
								class="blogger__author__btn justify-content-item tn-flex-col-center tn-flex-row-center" @click="showMenu(item.iid)">
								<!-- 为什么不放关注按钮，因为快餐文化的世界，关注按钮放在外面没必要 -->
								<text class="tn-icon-more-vertical tn-color-gray tn-text-bold tn-text-xxl"></text>
							</view>
						</view>

						<view
							class="blogger__desc tn-margin-top-sm tn-margin-bottom-sm tn-text-justify tn-flex-col-center tn-flex-row-left"
							@click="tn('/circlePages/details?iid='+item.iid)">
							<view v-for="(label_item,label_index) in item.label" :key="label_index"
								class="blogger__desc__label tn-float-left tn-margin-right tn-bg-gray--light tn-round tn-text-sm tn-text-bold">
								<text class="blogger__desc__label--prefix">#</text>
								<text class="tn-text-df">{{ label_item }}</text>
							</view>
							<!-- 不用限制长度了，因为发布的时候限制长度了-->
							<text v-if="!item.label || item.label.length < 4"
								class="blogger__desc__content tn-flex-1 tn-text-justify tn-text-df">{{ item.desc }}</text>
						</view>
						<block v-if="item.mainImage">
							<view v-if="[1,2,4].indexOf(item.mainImage.length) != -1" class="tn-padding-top-xs"
								@click="tn('/circlePages/details?iid='+item.iid)">
								<image v-for="(image_item,image_index) in item.mainImage" :key="image_index"
									class="blogger__main-image" :class="{
				        'blogger__main-image--1 tn-margin-bottom-sm': item.mainImage.length === 1,
				        'blogger__main-image--2 tn-margin-right-sm tn-margin-bottom-sm': item.mainImage.length === 2 || item.mainImage.length === 4
				      }" :src="image_item" mode="aspectFill"></image>
							</view>
							<view v-else class="tn-padding-top-xs" @click="tn('/circlePages/details?iid='+item.iid)">
								<tn-grid hoverClass="none" :col="3">
									<block v-for="(image_item,image_index) in item.mainImage" :key="image_index">
										<!-- #ifndef MP-WEIXIN -->
										<tn-grid-item style="width: 30%;margin: 10rpx;">
											<image class="blogger__main-image blogger__main-image--3" :src="image_item"
												mode="aspectFill"></image>
										</tn-grid-item>
										<!-- #endif-->
										<!-- #ifdef MP-WEIXIN -->
										<tn-grid-item style="width: 30%;margin: 10rpx;">
											<image class="blogger__main-image blogger__main-image--3" :src="image_item"
												mode="aspectFill"></image>
										</tn-grid-item>
										<!-- #endif-->
									</block>
								</tn-grid>
							</view>
						</block>

						<!-- <view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-top-xs">
							<view class="justify-content-item tn-color-gray tn-text-center">
								<view class="">
									<text class="blogger__count-icon tn-icon-footprint"></text>
									<text class="tn-padding-right">{{ item.collectionCount }}</text>
									<text class="blogger__count-icon tn-icon-message"></text>
									<text class="tn-padding-right">{{ item.commentCount }}</text>
									<text class="blogger__count-icon tn-icon-like"></text>
									<text class="">{{ item.likeCount }}</text>
									<button type="default" open-type="share" class="shareBtn" :data-id="item.iid"
									 data-type="dongtai" @click.stop="">
										<text class="blogger__count-icon tn-icon-share"></text>
									</button>
								</view>
							</view>
							<view class="justify-content-item tn-flex tn-flex-col-center">
								<view style="margin-right: 10rpx;margin-left: 20rpx;">
									<tn-avatar-group :lists="item.viewUser.latestUserAvatar"
										size="sm"></tn-avatar-group>
								</view>
								<text class="tn-color-gray">{{ item.viewUser.viewUserCount }}人</text>
							</view>
						</view> -->
						<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-top-xs">
							<view class="justify-content-item tn-color-gray tn-text-center">
								<view style="margin-right: 10rpx;margin-left: 20rpx;">
									<tn-avatar-group :lists="item.viewUser.latestUserAvatar" size="sm"></tn-avatar-group>
								</view>
								<!-- <text class="tn-color-gray">{{ item.viewUser.viewUserCount }}人</text> -->
							</view>
							<view class="justify-content-item tn-flex tn-flex-col-center">
								<view class="justify-content-item tn-flex tn-flex-col-center">
									<button type="default" open-type="share" class="shareBtn" :data-id="item.iid"
										data-type="dongtai" @click.stop="">
										<text class="blogger__count-icon tn-icon-share"></text>
									</button>
									<!-- <text class="tn-padding-right">{{ item.collectionCount }}</text> -->
									<text class="blogger__count-icon tn-icon-message"></text>
									<text class="tn-padding-right">{{ item.commentCount }}</text>
									<text class="blogger__count-icon tn-icon-like" @click.stop="dianzan(item)"></text>
									<text class="">{{ item.likeCount }}</text>
									<!-- <button type="default" open-type="share" class="shareBtn" :data-id="item.iid"
										data-type="dongtai" @click.stop="">
										<text class="blogger__count-icon tn-icon-share"></text>
									</button> -->
								</view>
							</view>
						</view>
					</view>

					<!-- 边距间隔 -->
					<view class="tn-strip-bottom" v-if="index != news.length - 1"></view>
				</block>

				<!-- 边距间隔 -->
				<view class="tn-strip-bottom"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import Tools from '@/tools/config.js'
	export default {
		name: 'TemplateCollect',
		mixins: [template_page_mixin],
		data() {
			return {
				news: [],
			}
		},
		onShow() {
			this.initData()
		},
		methods: {
			showMenu(id){
				uni.showActionSheet({
					itemList: ['修改','删除','刷新'],
					success: (res)=> {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if(res.tapIndex == 0){
							uni.navigateTo({
								url:"/circlePages/edit?id="+id
							})
						}else if(res.tapIndex == 1){
							// 删除
							this.deleteDongtai(id)
						}else if(res.tapIndex == 2){
							// 刷新
							this.flashDongtai(id)
						}
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
			flashDongtai(id){
				uni.showLoading()
				let theopenid = uni.getStorageSync('openid')
				let theunionid = uni.getStorageSync('unionid')
				uni.request({
					url: Tools.host + '/wshly.ashx',
					method: 'POST',
					data: {
						'lx': 'dongtai_user_upsj',
						'openid': theopenid,
						'unionid': theunionid,
						'iid': id
					},
					success: (res) => {
						//成功
						if (res.data.return_code == '1') {
							uni.showToast({
								title:'刷新完成',
								icon:"success"
							})
						} else {
							uni.showToast({
								title: res.data.return_msg,
								icon: "none"
							})
						}
					},
					fail: (res) => {
						console.log('失败' + res)
						uni.showModal({
							title: '失败，请稍后重试',
							showCancel: false
						})
					},
					complete() {
						uni.hideLoading()
					}
				});
			},
			deleteDongtai(id){
				uni.showModal({
					title:"温馨提示",
					content:"是否确认删除这条动态?",
					success:(res)=>{
						if(res.confirm){
							let theopenid = uni.getStorageSync('openid')
							let theunionid = uni.getStorageSync('unionid')
							uni.request({
								url: Tools.host + '/wshly.ashx',
								method: 'POST',
								data: {
									'lx': 'dongtai_user_del',
									'openid': theopenid,
									'unionid': theunionid,
									'iid': id
								},
								success: (res) => {
									//成功
									if (res.data.return_code == '1') {
										uni.showToast({
											title:'已删除',
											icon:"success"
										})
										this.initData()
									} else {
										uni.showToast({
											title: res.data.return_msg,
											icon: "none"
										})
									}
								},
								fail: (res) => {
									console.log('失败' + res)
									uni.showModal({
										title: '失败，请稍后重试',
										showCancel: false
									})
								}
							});
						}
					}
				})
			},
			initData() {
				let theopenid = uni.getStorageSync('openid')
				let theunionid = uni.getStorageSync('unionid')
				uni.request({
					url: Tools.host + '/wshly.ashx',
					method: 'POST',
					data: {
						'lx': 'dongtai_my',
						'openid': theopenid,
						'unionid': theunionid,
					},
					success: (res) => {
						//成功
						if (res.data.return_code == '1') {
							const a = JSON.parse(res.data.data)
							console.log("1111", a)
							this.news = a
						} else {
							uni.showToast({
								title: res.data.return_msg,
								icon: "none"
							})
						}
					},
					fail: (res) => {
						console.log('失败' + res)
						uni.showModal({
							title: '失败，请稍后重试',
							showCancel: false
						})
					}
				});
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.shareBtn{
		display:inline-flex;
		background-color: unset;
		line-height: unset;
	}
	.shareBtn::before{
		all:unset;
	}
	.shareBtn::after{
		all:unset;
	}
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}
	/* 文章内容 start*/
	.blogger {
		&__item {
			padding: 30rpx;
		}
	
		&__author {
			&__btn {
				margin-right: -12rpx;
				opacity: 0.5;
			}
		}
	
		&__desc {
			line-height: 55rpx;
	
			&__label {
				padding: 0 20rpx;
				margin: 0rpx 18rpx 0 0;
	
				&--prefix {
					color: #00FFC8;
					padding-right: 10rpx;
				}
			}
	
			&__content {}
		}
	
		&__content {
			margin-top: 18rpx;
			padding-right: 18rpx;
	
			&__data {
				line-height: 46rpx;
				text-align: justify;
				overflow: hidden;
				transition: all 0.25s ease-in-out;
	
			}
	
			&__status {
				margin-top: 10rpx;
				font-size: 26rpx;
				color: #82B2FF;
			}
		}
	
		&__main-image {
			border-radius: 16rpx;
	
			&--1 {
				max-width: 80%;
				max-height: 300rpx;
			}
	
			&--2 {
				max-width: 260rpx;
				max-height: 260rpx;
			}
	
			&--3 {
				height: 212rpx;
				width: 100%;
			}
		}
	
		&__count-icon {
			font-size: 40rpx;
			padding-right: 5rpx;
		}
	
		&__ad {
			width: 100%;
			height: 500rpx;
			transform: translate3d(0px, 0px, 0px) !important;
	
			::v-deep .uni-swiper-slide-frame {
				transform: translate3d(0px, 0px, 0px) !important;
			}
	
			.uni-swiper-slide-frame {
				transform: translate3d(0px, 0px, 0px) !important;
			}
	
			&__item {
				position: absolute;
				width: 100%;
				height: 100%;
				transform-origin: left center;
				transform: translate3d(100%, 0px, 0px) scale(1) !important;
				transition: transform 0.25s ease-in-out;
				z-index: 1;
	
				&--0 {
					transform: translate3d(0%, 0px, 0px) scale(1) !important;
					z-index: 4;
				}
	
				&--1 {
					transform: translate3d(13%, 0px, 0px) scale(0.9) !important;
					z-index: 3;
				}
	
				&--2 {
					transform: translate3d(26%, 0px, 0px) scale(0.8) !important;
					z-index: 2;
				}
			}
	
			&__content {
				border-radius: 40rpx;
				width: 640rpx;
				height: 500rpx;
				overflow: hidden;
			}
	
			&__image {
				width: 100%;
				height: 100%;
			}
		}
	}
	
	/* 文章内容 end*/
	
	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}
</style>